package com.ctrl.riveradministrator.http.download;

import android.content.Context;
import android.content.SharedPreferences;

import com.ctrl.riveradministrator.common.Constants;

public class SPDownloadUtil {

    private static SharedPreferences mSharedPreferences;
    private static SPDownloadUtil instance;

    private SPDownloadUtil() {
    }

    public static SPDownloadUtil getInstance(Context context) {
        if (mSharedPreferences == null || instance == null) {
            synchronized (SPDownloadUtil.class) {
                if (mSharedPreferences == null || instance == null) {
                    instance = new SPDownloadUtil();
                    mSharedPreferences = context.getSharedPreferences(Constants.DOWNLOAD_SP, Context.MODE_PRIVATE);
                }
            }
        }
        return instance;
    }

    public boolean clear() {
        return mSharedPreferences.edit().clear().commit();
    }

    public boolean save(String key, long value) {
        return mSharedPreferences.edit().putLong(key, value).commit();
    }

    public long get(String key, long defValue) {
        return mSharedPreferences.getLong(key, defValue);
    }

}
